const joi = require('joi')
/*
string只允许为字符串
alphanum只允许为a-z和A-Z和0-9
min最小长度 max最大长度
pattern传入正则表达式
required必填项
*/

// 对id的验证
const id = joi.required()
// 对name的验证
const name = joi.string().pattern(/(^([a-zA-Z]+\s)*[a-zA-Z]+$)|(^[\u4e00-\u9fa5]+$)/).required()
// 对gender的验证
const gender = joi.string().pattern(/^(男|女){1}$/).required()
// 对email的验证
const email = joi.string().pattern(/^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/).required()
// 对oldPassword的验证
const oldPassword = joi.string().pattern(/^(?![0-9]+$)[a-z0-9]{1,50}$/).min(6).max(12).required()
// 对newPassword的验证
const newPassword = joi.string().pattern(/^(?![0-9]+$)[a-z0-9]{1,50}$/).min(6).max(12).required()
// 对账号的验证
const account = joi.string().alphanum().min(6).max(12).required()


exports.password_limit = {
    body: {
        id,
        oldPassword,
        newPassword
    }
}

exports.name_limit = {
    body: {
        id,
        name
    }
}
exports.gender_limit = {
    body: {
        id,
        gender
    }
}
exports.email_limit = {
    // 表示对req.body里的数据进行验证
    body: {
        id,
        email
    }
}
exports.forgetPassword_limit = {
    body: {
        account,
        newPassword
    }
}